package com.tywj.panda.customer.usercenter.center

import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.tywj.panda.customer.common.http.PDStringCallback
import com.tywj.panda.customer.common.view.base.MyBaseActivity
import com.tywj.lib.core.common.extension.onClick
import com.tywj.lib.core.common.util.BarUtil
import com.tywj.lib.core.common.util.ResourcesUtil
import com.tywj.panda.customer.usercenter.R
import com.tywj.panda.customer.usercenter.api.UserCenterApi
import com.tywj.panda.customer.usercenter.route.UserCenterRoute
import kotlinx.android.synthetic.main.user_activity_feedback.*

@Route(path = UserCenterRoute.USER_FEEDBACK)
class UserFeedBackActivity : MyBaseActivity() {

    override fun getLayoutID(): Int = R.layout.user_activity_feedback

    private var content = ""

    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)
        BarUtil.setStatusBarColor(this, ResourcesUtil.getColor(R.color.common_white))
        BarUtil.setStatusBarLightMode(this.window, true)
    }

    override fun initListener() {
        super.initListener()

        btnSubmit.onClick {

            content = etFeedBack.text.toString()

            if (content.isEmpty()) {
                shortToast("反馈内容不能为空")
            } else {
                loadData(content)
            }
        }
    }

    private fun loadData(content: String) {
        showLoadingDialog(ResourcesUtil.getString(R.string.common_loading))
        UserCenterApi.saveFeedBack(content).attachToLifecycle(this).execute(object : PDStringCallback() {
            override fun success(message: String) {
                finish()
            }

            override fun error(code: Int, message: String) {
                super.error(code, message)
                shortToast(message)
            }

            override fun onComplete() {
                super.onComplete()
                dismissLoadingDialog()
            }
        })
    }
}